-- $LastChangedDate: 2009-02-26 20:11:37 +0000 (Thu, 26 Feb 2009) $
-- $LastChangedBy: ermite_chevelu@hotmail.com $
-- $LastChangedRevision: 22 $

RvRStats = {}

local window = "CharacterWindowRvRStats"
RvRStats.Window = window
local oldShow = nil
RvRStats.MESSAGES = {}
RvRStats.Messages = {}

---- Init ----
function RvRStats.Init()
   RvRStats.InitLocale()
   oldShow = CharacterWindow.OnShown
   CharacterWindow.OnShown = RvRStats.OnShown
end

function RvRStats.OnShown()
   RvRStats.UpdateWindow()
   oldShow()
end

function RvRStats.InitLocale()
	local switch = {
		[SystemData.Settings.Language.ENGLISH] = L"enUS",
		[SystemData.Settings.Language.FRENCH] = L"frFR",
		[SystemData.Settings.Language.GERMAN] = L"deDE",
		[SystemData.Settings.Language.ITALIAN] = L"itIT",
		[SystemData.Settings.Language.SPANISH] = L"esES",
		[SystemData.Settings.Language.RUSSIAN] = L"ruRU"
	}
		
	local res = switch[SystemData.Settings.Language.active] 
	if not res then
		res = L"enUS"
	end

    RvRStats.Messages = RvRStats.MESSAGES[res]
end

local function getMessage(key)
    return RvRStats.Messages[key]
end

local function getClassName(speciesData)
   return speciesData.name
end

local function getKillCount(speciesData)
   return StringToWString(string.format("%d", speciesData.killCount))
end

function RvRStats.UpdateWindow()
   local safeDeaths = math.max(GameData.Player.RvRStats.LifetimeDeaths, 1)
   local KDRatio = (GameData.Player.RvRStats.LifetimeKills / safeDeaths)
   local DBDRatio = (GameData.Player.RvRStats.LifetimeDeathBlows / safeDeaths)
   local race = GameData.Player.race.id
   
   local classA_Name = StringToWString("???")
   local classB_Name = StringToWString("???")
   local classC_Name = StringToWString("???")
   local classD_Name = StringToWString("???")
   local classE_Name = StringToWString("???")
   local classF_Name = StringToWString("???")
   local classG_Name = StringToWString("???")
   local classH_Name = StringToWString("???")
   local classI_Name = StringToWString("???")
   local classJ_Name = StringToWString("???")
   local classK_Name = StringToWString("???")
   local classL_Name = StringToWString("???")
   
   local classA_KillCount = StringToWString("0")
   local classB_KillCount = StringToWString("0")
   local classC_KillCount = StringToWString("0")
   local classD_KillCount = StringToWString("0")
   local classE_KillCount = StringToWString("0")
   local classF_KillCount = StringToWString("0")
   local classG_KillCount = StringToWString("0")
   local classH_KillCount = StringToWString("0")
   local classI_KillCount = StringToWString("0")
   local classJ_KillCount = StringToWString("0")
   local classK_KillCount = StringToWString("0")
   local classL_KillCount = StringToWString("0")
   
   if race == 2 or race == 3 or race == 5 or race == 7 then
      local subTypeData = TomeGetBestiarySubTypeData( 16 ) --human
      if subTypeData then
         for index, speciesData in ipairs( subTypeData.species ) do
            if speciesData.id == 48 and speciesData.isUnlocked == true then --bright wizard
               classA_Name = getClassName(speciesData)
               classA_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 49 and speciesData.isUnlocked == true then --kotbs
               classB_Name = getClassName(speciesData)
               classB_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 50 and speciesData.isUnlocked == true then --warrior priest
               classC_Name = getClassName(speciesData)
               classC_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 51 and speciesData.isUnlocked == true then --witch hunter
               classD_Name = getClassName(speciesData)
               classD_KillCount = getKillCount(speciesData)
            end
         end
      end
      
      local subTypeData = TomeGetBestiarySubTypeData( 13 ) --dwarf
      if subTypeData then
         for index, speciesData in ipairs( subTypeData.species ) do
            if speciesData.id == 42 and speciesData.isUnlocked == true then --engineer
               classE_Name = getClassName(speciesData)
               classE_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 43 and speciesData.isUnlocked == true then --slayer
               classF_Name = getClassName(speciesData)
               classF_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 44 and speciesData.isUnlocked == true then --ironbreaker
               classG_Name = getClassName(speciesData)
               classG_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 45 and speciesData.isUnlocked == true then --runepriest
               classH_Name = getClassName(speciesData)
               classH_KillCount = getKillCount(speciesData)
            end
         end
      end
      
      local subTypeData = TomeGetBestiarySubTypeData( 14 ) -- high elf
      if subTypeData then
         for index, speciesData in ipairs( subTypeData.species ) do
            if speciesData.id == 75 and speciesData.isUnlocked == true then --archmage
               classI_Name = getClassName(speciesData)
               classI_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 76 and speciesData.isUnlocked == true then --white lion
               classJ_Name = getClassName(speciesData)
               classJ_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 77 and speciesData.isUnlocked == true then --shadow warrior
               classK_Name = getClassName(speciesData)
               classK_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 78 and speciesData.isUnlocked == true then --swordmaster
               classL_Name = getClassName(speciesData)
               classL_KillCount = getKillCount(speciesData)
            end
         end
      end
   end
   
   if race == 1 or race == 4 or race == 6  then
      local subTypeData = TomeGetBestiarySubTypeData( 16 ) --human
      if subTypeData then
         for index, speciesData in ipairs( subTypeData.species ) do
            if speciesData.id == 14 then --chosen
               classA_Name = getClassName(speciesData)
               classA_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 15 then --magus
               classB_Name = getClassName(speciesData)
               classB_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 16 then --marauder
               classC_Name = getClassName(speciesData)
               classC_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 17 then --zealot
               classD_Name = getClassName(speciesData)
               classD_KillCount = getKillCount(speciesData)
            end
         end
      end
      
      local subTypeData = TomeGetBestiarySubTypeData( 15 ) --greenskin
      if subTypeData then
         for index, speciesData in ipairs( subTypeData.species ) do
            if speciesData.id == 63 then --shaman
               classE_Name = getClassName(speciesData)
               classE_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 64 then --squig herder
               classF_Name = getClassName(speciesData)
               classF_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 92 then --black orc
               classG_Name = getClassName(speciesData)
               classG_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 93 then --choppa
               classH_Name = getClassName(speciesData)
               classH_KillCount = getKillCount(speciesData)
            end
            
         end
      end
      
      local subTypeData = TomeGetBestiarySubTypeData( 14 ) -- dark elf
      if subTypeData then
         for index, speciesData in ipairs( subTypeData.species ) do
            if speciesData.id == 31 then --witch elf
               classI_Name = getClassName(speciesData)
               classI_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 32 then --disciple of khaine
               classJ_Name = getClassName(speciesData)
               classJ_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 33 then --blackguard
               classK_Name = getClassName(speciesData)
               classK_KillCount = getKillCount(speciesData)
            end
            
            if speciesData.id == 34 then --sorcerer
               classL_Name = getClassName(speciesData)
               classL_KillCount = getKillCount(speciesData)
            end
         end
      end
   end
   
   LabelSetText(window.."Header", GameData.Player.name)
   LabelSetText(window.."Title", getMessage("RR") .. L": " .. GameData.Player.Renown.curRank .. L"   " .. getMessage("TITLE") .. L": " .. GameData.Player.Renown.curTitle)
   LabelSetText(window.."LifetimeK", getMessage("LIFETIME_KILLS")..L": " .. (GameData.Player.RvRStats.LifetimeKills) .. L" (" .. (GameData.Player.RvRStats.SessionKills) .. L")")
   LabelSetText(window.."LifetimeDB", getMessage("LIFETIME_DEATHBLOWS")..L": " .. (GameData.Player.RvRStats.LifetimeDeathBlows))
   LabelSetText(window.."LifetimeD", getMessage("LIFETIME_DEATHS")..L": " .. (GameData.Player.RvRStats.LifetimeDeaths))
   LabelSetText(window.."LifetimeRatioKD", getMessage("LIFETIME_RATIO_KILL_DEATH")..(StringToWString(string.format(": %.2f" , KDRatio))))
   LabelSetText(window.."LifetimeRatioDBD", getMessage("LIFETIME_RATIO_DEATHBLOW_DEATH")..(StringToWString(string.format(": %.2f" , DBDRatio))))
   LabelSetText(window.."ClassKills", getMessage("CLASS_KILLS"))
   
   LabelSetText(window.."ClassA_Name", classA_Name .. L" : ")
   LabelSetText(window.."ClassA_KillCount", classA_KillCount)
   
   LabelSetText(window.."ClassB_Name", classB_Name .. L" : ")
   LabelSetText(window.."ClassB_KillCount", classB_KillCount)
   
   LabelSetText(window.."ClassC_Name", classC_Name .. L" : ")
   LabelSetText(window.."ClassC_KillCount", classC_KillCount)
   
   LabelSetText(window.."ClassD_Name", classD_Name .. L" : ")
   LabelSetText(window.."ClassD_KillCount", classD_KillCount)
   
   LabelSetText(window.."ClassE_Name", classE_Name .. L" : ")
   LabelSetText(window.."ClassE_KillCount", classE_KillCount)
   
   LabelSetText(window.."ClassF_Name", classF_Name .. L" : ")
   LabelSetText(window.."ClassF_KillCount", classF_KillCount)
   
   LabelSetText(window.."ClassG_Name", classG_Name .. L" : ")
   LabelSetText(window.."ClassG_KillCount", classG_KillCount)
   
   LabelSetText(window.."ClassH_Name", classH_Name .. L" : ")
   LabelSetText(window.."ClassH_KillCount", classH_KillCount)
   
   LabelSetText(window.."ClassI_Name", classI_Name .. L" : ")
   LabelSetText(window.."ClassI_KillCount", classI_KillCount)
   
   LabelSetText(window.."ClassJ_Name", classJ_Name .. L" : ")
   LabelSetText(window.."ClassJ_KillCount", classJ_KillCount)
   
   LabelSetText(window.."ClassK_Name", classK_Name .. L" : ")
   LabelSetText(window.."ClassK_KillCount", classK_KillCount)
   
   LabelSetText(window.."ClassL_Name", classL_Name .. L" : ")
   LabelSetText(window.."ClassL_KillCount", classL_KillCount)
end
